package com.recsmile.shiro.realm;

import org.apache.shiro.authc.AuthenticationException;
import org.apache.shiro.authc.AuthenticationInfo;
import org.apache.shiro.authc.AuthenticationToken;
import org.apache.shiro.authc.SimpleAuthenticationInfo;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.authz.AuthorizationInfo;
import org.apache.shiro.realm.AuthorizingRealm;
import org.apache.shiro.subject.PrincipalCollection;
import org.springframework.beans.factory.annotation.Autowired;

import com.recsmile.bo.User;
import com.recsmile.mapper.UserMapper;

public class ImOkShiroRealm extends AuthorizingRealm {

	
	@Autowired
	private UserMapper userMapper;
	
	
	@Override
	protected AuthorizationInfo doGetAuthorizationInfo(
			PrincipalCollection principals) {
		return null;
	}

	@Override
	protected AuthenticationInfo doGetAuthenticationInfo(
			AuthenticationToken token) throws AuthenticationException {
		User user = userMapper.selectByName(((UsernamePasswordToken)token).getUsername());
		return user == null ? null : new SimpleAuthenticationInfo(user.getAccount(), user.getPassword(), user.getNickname());
	}

}
